import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/afterSales/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询索赔历史'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询索赔单详情'
});
const getApplyHistoryListDesc = formatMessage({
    id: 'api.message.getApplyHistoryListDesc',
    defaultMessage: '查询索赔预申请单'
});
const getApplyDetailDesc = formatMessage({
    id: 'api.message.getApplyDetailDesc',
    defaultMessage: '查询索赔预申请单详情'
});
const getSubClaimHistoryListDesc = formatMessage({
    id: 'api.message.getSubClaimHistoryListDesc',
    defaultMessage: '查询二级服务站索赔历史'
});
const getSubClaimDetailDesc = formatMessage({
    id: 'api.message.getSubClaimDetailDesc',
    defaultMessage: '查询二级服务站索赔单详情'
});
const getSubClaimApplyHistoryListDesc = formatMessage({
    id: 'api.message.getSubClaimApplyHistoryListDesc',
    defaultMessage: '查询二级服务站索赔预申请单'
});
const getSubClaimApplyDetailDesc = formatMessage({
    id: 'api.message.getSubClaimApplyDetailDesc',
    defaultMessage: '查询二级服务站索赔预申请单详情'
});
// 查询订单列表
export const getHistoryList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claims/history?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/claims/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));

// 查询索赔预申请列表
export const getApplyHistoryList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimApplies/history?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getApplyHistoryListDesc));
};
// 查询索赔预申请详情
export const getApplyDetail = id =>
    request(`${baseUrl}/claimApplies/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getApplyDetailDesc));

// 查询订单列表
export const getSubClaimHistoryList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subClaims/history?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getSubClaimHistoryListDesc));
};
// 查询详情
export const getSubClaimDetail = id =>
    request(`${baseUrl}/subClaims/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getSubClaimDetailDesc));

// 查询二级服务站索赔预申请
export const getSubClaimApplyHistoryList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subClaimApplies/history?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getSubClaimApplyHistoryListDesc));
};
// 查询二级服务站索赔预申请详情
export const getSubClaimApplyDetail = id =>
    request(`${baseUrl}/subClaimApplies/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getSubClaimApplyDetailDesc));
